class Descriptor < ActiveRecord::Base

  define_index do
    indexes :description, sortable => true
    set_property :enable_star => true
    set_property :min_prefix_len => 3
  end

  def self.engine_search_by_description description
    return Descriptor.search description, :match_mode => :any, :star => true
  end

  def self.search_selector(search_name, page)
    items_per_page = count_record_per_page :tags
    order = "description"
    conditions_clauses = []
    conditions_options = []

    if !search_name.nil? && search_name != ""
      conditions_clauses << "upper(description) like upper(?)"
      conditions_options << "%#{search_name}%"
    end
    conditions = [conditions_clauses.join(" AND "), conditions_options].flatten

    @descriptors = paginate :per_page => items_per_page,:page => page, :conditions => conditions, :order => order
    return @descriptors
  end
end
